package com.dongjiantong.farmrecords.serviceImpl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.dubbo.config.annotation.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.dongjiantong.biz.enums.EarMarkType;
import com.dongjiantong.biz.enums.ReportType;
import com.dongjiantong.biz.model.EarMarkLife;
import com.dongjiantong.biz.service.EarMarkLifeWriteService;
import com.dongjiantong.biz.service.EarMarksWriteService;
import com.dongjiantong.biz.service.FarmStockService;
import com.dongjiantong.biz.service.StablesService;
import com.dongjiantong.common.exceptions.HttpCode;
import com.dongjiantong.common.exceptions.OPServerException;
import com.dongjiantong.common.utils.ReportNumberMakerUtil;
import com.dongjiantong.common.web.sso.LoginInfo;
import com.dongjiantong.farmrecords.enums.FarmRecordsFileEnum;
import com.dongjiantong.farmrecords.enums.FarmRecordsNumberStatus;
import com.dongjiantong.farmrecords.enums.ProductRelateTypeEnum;
import com.dongjiantong.farmrecords.mapper.FarmRecordsFileMapper;
import com.dongjiantong.farmrecords.mapper.FarmRecordsHarmlessesMapper;
import com.dongjiantong.farmrecords.model.FarmRecordsFile;
import com.dongjiantong.farmrecords.model.FarmRecordsHarmlesses;
import com.dongjiantong.farmrecords.model.FarmRecordsProduction;
import com.dongjiantong.farmrecords.service.FarmRecordsFileService;
import com.dongjiantong.farmrecords.service.FarmRecordsHarmlessesService;
import com.dongjiantong.farmrecords.service.FarmRecordsProductionService;
import com.dongjiantong.mybatis.ServiceMybatis;
import com.dongjiantong.user.enums.FarmsEnum;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 防疫中心 -- 非集中处理无害化
 * @author Lee
 * @date 2018/1/9
 */
@Slf4j
@Service(version = "1.0.0")
public class FarmRecordsHarmlessesServiceImpl extends ServiceMybatis<FarmRecordsHarmlesses> implements FarmRecordsHarmlessesService {
    @Resource
    private FarmRecordsHarmlessesMapper farmRecordsHarmlessesMapper;
    @Resource
    private FarmRecordsFileMapper farmRecordsFileMapper;

    @Resource
    public FarmRecordsProductionService farmRecordsProductionService;
    @Resource
    public FarmRecordsFileService farmRecordsFileService;

    @Reference(version = "1.0.0")
    public StablesService stablesService;
    @Reference(version = "1.0.0")
    public FarmStockService farmStockService;
    @Reference(version = "1.0.0")
    private EarMarksWriteService earMarksWriteService;
    @Reference(version = "1.0.0")
    private EarMarkLifeWriteService earMarkLifeWriteService;

    /**
     * (政府端)
     * 根据养殖场ids,起止时间或者状态查询非集中无害化处理记录 (条件都可以为空,表示查询所有)
     * @param map
     * @param pageNum
     * @param pageSize
     * @return  Response<PageInfo<FarmRecordsHarmlesses>>
     */
    @Override
    public PageInfo<FarmRecordsHarmlesses> selectByMap(Integer pageNum, Integer pageSize, Map<String, Object> map) {
        try {
            if (farmRecordsHarmlessesMapper == null){
                throw new OPServerException("farmRecordsHarmlessesMapper 为null,请检查");
            }
            PageHelper.startPage(pageNum,pageSize);
            //查询有效单据
            map.put("delete_flag", FarmRecordsNumberStatus.EFFECTIVE.getCode());
            //查询已启用的养殖场
            map.put("farmStatus", FarmsEnum.status_true.getCode());
            List<FarmRecordsHarmlesses> farmRecordsHarmlessesList = farmRecordsHarmlessesMapper.selectByMap(map);

            if (farmRecordsHarmlessesList.size() > 0){
                this.setPicOrVideoList(farmRecordsHarmlessesList);
            }

            return new PageInfo<FarmRecordsHarmlesses>(farmRecordsHarmlessesList);
        } catch (Exception e) {
            log.error(e.getMessage());
            e.printStackTrace();
            throw new OPServerException(HttpCode.INTERNAL_SERVER_ERROR,HttpCode.INTERNAL_SERVER_ERROR.getMessage());
        }
    }

    /**
     * 养殖端按照单据状态分页查询列表
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @Override
    public PageInfo<FarmRecordsHarmlesses> selectListByStatus(Integer pageNum, Integer pageSize, Integer status, Long farmId, Integer nonBull) {
        PageHelper.startPage(pageNum,pageSize);

        Map<String,Object> map = Maps.newHashMap();

        if (status != null){
            map.put("status",status);
        }
        map.put("farm_id",farmId);

        map.put("delete_flag",FarmRecordsNumberStatus.EFFECTIVE.getCode());

        map.put("animal_second_non_bull",nonBull);

        List<FarmRecordsHarmlesses> farmRecordsHarmlessesList = farmRecordsHarmlessesMapper.selectListByStatus(map);

        if (farmRecordsHarmlessesList.size() > 0) {
            this.setPicOrVideoList(farmRecordsHarmlessesList);
        }

        return new PageInfo<FarmRecordsHarmlesses>(farmRecordsHarmlessesList);
    }

    /**
     * 设置关联信息(视频,图片)
     * @param farmRecordsHarmlessesList
     */
    public void setPicOrVideoList(List<FarmRecordsHarmlesses> farmRecordsHarmlessesList){
        if (farmRecordsFileMapper == null){
            throw new OPServerException("farmRecordsFileMapper 为null,请检查");
        }
        List<Long> ids = farmRecordsHarmlessesList.stream().map(farmRecordsHarmlessesNoCenter -> farmRecordsHarmlessesNoCenter.getId()).collect(Collectors.toList());

        List<Integer> type2List = Lists.newArrayList(FarmRecordsFileEnum.PHOTO.getCode(),FarmRecordsFileEnum.VIDEO.getCode());

        Map map = Maps.newHashMap();
        map.put("relevanceIds",ids);
        map.put("listType2",type2List);
        map.put("type1",FarmRecordsFileEnum.HARMLESSESNOCENTER.getCode());
        //查询对应的图片,视频
        List<FarmRecordsFile> farmRecordsFileList = farmRecordsFileMapper.selectPicOrVideoListByRelevanceIds(map);

        if (farmRecordsFileList.size() > 0){
            for (FarmRecordsHarmlesses farmRecordsHarmlesses : farmRecordsHarmlessesList){
                this.setPicOrVideoByObject(farmRecordsHarmlesses,farmRecordsFileList);
            }
        }
    }

    @Override
    public FarmRecordsHarmlesses setPicOrVideoByObject(FarmRecordsHarmlesses farmRecordsHarmlesses, List<FarmRecordsFile> farmRecordsFileList) {
        List<String> picList = Lists.newArrayList();
        String video = null;
        for (FarmRecordsFile farmRecordsFile : farmRecordsFileList){
            if ((farmRecordsHarmlesses.getId()).equals(farmRecordsFile.getRelevance_id())){
                //获取图片
                if ((FarmRecordsFileEnum.PHOTO.getCode()).equals(farmRecordsFile.getType2())){
                    JSONArray jsonArray = JSON.parseArray(farmRecordsFile.getAddress());
                    List<String> list = jsonArray.toJavaList(String.class);
                    picList = list;
                }
                //获取视频
                if ((FarmRecordsFileEnum.VIDEO.getCode()).equals(farmRecordsFile.getType2())){
                    video = farmRecordsFile.getAddress();
                }
            }
        }
        //设置图片
        if (picList.size() > 0){
            farmRecordsHarmlesses.setPicList(picList);
        } else {
            farmRecordsHarmlesses.setPicList(Lists.newArrayList());
        }
        //设置视频
        if (!Strings.isNullOrEmpty(video)){
            farmRecordsHarmlesses.setVideo_toObject(video);
        }

        return farmRecordsHarmlesses;
    }

    /**
     * 根据牛档案关联id 查询对应非集中处理无害化
     * @param cowRecordId
     * @return
     */
    @Override
    public FarmRecordsHarmlesses selectBullHarmlessesNoCenter(Long cowRecordId){
        Map<String,Object> map = Maps.newHashMap();
        map.put("cow_record_id",cowRecordId);

        FarmRecordsHarmlesses farmRecordsHarmlesses = farmRecordsHarmlessesMapper.selectOneByMap(map);
        return farmRecordsHarmlesses;
    }

    /**
     * 根据牛档案单据ids 查询无害化记录
     * @param ids
     * @return
     */
    @Override
    public List<Map<String, Object>> selectHarmlessesNoCenterCount(List<Long> ids) {
        Map<String,Object> map = Maps.newHashMap();
        map.put("ids",ids);
        List<Map<String,Object>> result = farmRecordsHarmlessesMapper.selectHarmlessesNoCenterCount(map);
        return result;
    }

    /**
     * 根据单据前缀查找表中最大单据号
     * @param prefix
     * @return
     */
    @Override
    public String findMaxNumber(String prefix) {
        return farmRecordsHarmlessesMapper.findMaxNumber(prefix);
    }

    /**
     * 新增非集中处理无害化单据id
     * @param farmrecordsHarmlesses
     * @return
     */
    @Override
    public Map<String,Object> createOne(LoginInfo loginInfo, FarmRecordsHarmlesses farmrecordsHarmlesses, Integer toStatus, Integer isFrom) {
        if (farmrecordsHarmlesses == null){
            throw new OPServerException("farmRecordsHarmlessesMapper 为null,请检查");
        }

        Map<String,Object> result = Maps.newHashMap();

        try {
            Integer fromStatus = farmrecordsHarmlesses.getStatus();

            //todo 生成单据号
            //单据生成规则暂未定(此处为测试)
            String prefix = "FWHN";
            prefix = ReportNumberMakerUtil.createPrefix(prefix,loginInfo.getProvinceId(),loginInfo.getCityId(),loginInfo.getRegionId());
            String maxNumber = farmRecordsHarmlessesMapper.findMaxNumber(prefix);
            String number = ReportNumberMakerUtil.create(prefix,maxNumber);
            farmrecordsHarmlesses.setNumber(number);

            farmrecordsHarmlesses.setProvince_id(loginInfo.getProvinceId());
            farmrecordsHarmlesses.setCity_id(loginInfo.getCityId());
            farmrecordsHarmlesses.setRegion_id(loginInfo.getRegionId());
            farmrecordsHarmlesses.setStreet_id(loginInfo.getStreetId());
            farmrecordsHarmlesses.setVillage_id(loginInfo.getVillageId());

            farmrecordsHarmlesses.setDelete_flag(FarmRecordsNumberStatus.EFFECTIVE.getCode());

            //todo 单据从状态到状态 (非集中处理不需要更新尸体库信息)
            if (fromStatus == 0 && toStatus == null) {
                //直接暂存
                farmRecordsHarmlessesMapper.createOne(farmrecordsHarmlesses);
            }else if (!fromStatus.equals(toStatus) && FarmRecordsNumberStatus.SUBMIT.getCode().equals(toStatus)) {
                //直接提交
                farmrecordsHarmlesses.setStatus(toStatus);
                farmRecordsHarmlessesMapper.createOne(farmrecordsHarmlesses);

                //todo 新建一条生产记录单据
                //自己做的无害化单据,需要新建一条生产记录
                if (isFrom == 2) {
                    FarmRecordsProduction farmRecordsProduction = createFarmRecordsProduction(farmrecordsHarmlesses,isFrom);

                    farmRecordsProductionService.createOne(loginInfo,farmRecordsProduction,FarmRecordsNumberStatus.SUBMIT.getCode(),2);
                }

                //todo 对选择的耳标操作
                List<String> earTogNumberList = farmrecordsHarmlesses.getEar_tag_number();

                List<String> earTogNumbers = Lists.newArrayList();
                for (String earTogNumber : earTogNumberList) {
                    if (!Strings.isNullOrEmpty(earTogNumber)) {
                        earTogNumbers.add(earTogNumber);
                    }
                }

                if (earTogNumbers.size() > 0) {
                    //更新耳标的状态
                    Map<String,Object> earParam = Maps.newHashMap();
                    earParam.put("markNumbers",earTogNumbers);
                    earParam.put("status", EarMarkType.status_output.getCode());
                    earParam.put("outedAt",new Date());

                    earMarksWriteService.updateMarks(earParam);

                    //耳标的一生 更新
                    List<String> list = Lists.newArrayList();
                    for (String earTogNumber : earTogNumberList) {
                        if (!Strings.isNullOrEmpty(earTogNumber)) {
                            list.add(earTogNumber);
                        }
                    }
                }
               /*Map<String,Object> map = Maps.newHashMap();
                map.put("markNumbers",list);
                map.put("",null);

                earMarkLifeWriteService.updateMarks(map);*/

            }

            if (farmrecordsHarmlesses.getId() != null) {
                result.put("receiptId", farmrecordsHarmlesses.getId());
            }

            if (farmrecordsHarmlesses.getId() != null) {
                this.insertPicOrVideo(farmrecordsHarmlesses);
            }

            //todo 生成政府操作记录

            return result;
        } catch (Exception e) {

            throw new OPServerException(HttpCode.DATA_CREATE_FAIL,HttpCode.DATA_CREATE_FAIL.getMessage());
        }
    }

    /**
     * 创建牛档案无害化
     * @param loginInfo
     * @param farmRecordsHarmlesses
     * @param toStatus
     * @param i
     * @return
     */
    @Override
    public Map<String, Object> createCowOne(LoginInfo loginInfo, FarmRecordsHarmlesses farmRecordsHarmlesses, Integer toStatus, int i) {
        if (farmRecordsHarmlesses == null){
            throw new OPServerException("farmRecordsHarmlessesMapper 为null,请检查");
        }

        Map<String,Object> result = Maps.newHashMap();

        try {
            Integer fromStatus = farmRecordsHarmlesses.getStatus();

            //todo 生成单据号
            //单据生成规则暂未定(此处为测试)
            String prefix = "FWHN";
            prefix = ReportNumberMakerUtil.createPrefix(prefix, loginInfo.getProvinceId(), loginInfo.getCityId(), loginInfo.getRegionId());
            String maxNumber = farmRecordsHarmlessesMapper.findMaxNumber(prefix);
            String number = ReportNumberMakerUtil.create(prefix, maxNumber);
            farmRecordsHarmlesses.setNumber(number);

            farmRecordsHarmlesses.setProvince_id(loginInfo.getProvinceId());
            farmRecordsHarmlesses.setCity_id(loginInfo.getCityId());
            farmRecordsHarmlesses.setRegion_id(loginInfo.getRegionId());
            farmRecordsHarmlesses.setStreet_id(loginInfo.getStreetId());
            farmRecordsHarmlesses.setVillage_id(loginInfo.getVillageId());

            farmRecordsHarmlesses.setDelete_flag(FarmRecordsNumberStatus.EFFECTIVE.getCode());

            //todo 单据从状态到状态 (非集中处理不需要更新尸体库信息)
            if (fromStatus == 0 && toStatus == null) {
                //直接暂存
                farmRecordsHarmlessesMapper.createOne(farmRecordsHarmlesses);
            } else if (!fromStatus.equals(toStatus) && FarmRecordsNumberStatus.SUBMIT.getCode().equals(toStatus)) {
                //直接提交
                farmRecordsHarmlesses.setStatus(toStatus);
                farmRecordsHarmlessesMapper.createOne(farmRecordsHarmlesses);

                //todo 新建一条生产记录单据
                /*//自己做的无害化单据,需要新建一条生产记录
                if (isFrom == 2) {
                    FarmRecordsProduction farmRecordsProduction = createFarmRecordsProduction(farmRecordsHarmlesses,isFrom);

                    farmRecordsProductionService.createOne(loginInfo,farmRecordsProduction,FarmRecordsNumberStatus.SUBMIT.getCode(),2);
                }*/
            }

            if (farmRecordsHarmlesses.getId() != null) {
                result.put("receiptId", farmRecordsHarmlesses.getId());
            }

            if (farmRecordsHarmlesses.getId() != null) {
                this.insertPicOrVideo(farmRecordsHarmlesses);
            }

            //todo 生成政府操作记录

            return result;

        }catch (Exception e) {
            e.printStackTrace();
            throw new OPServerException(HttpCode.DATA_CREATE_FAIL,HttpCode.DATA_CREATE_FAIL.getMessage());
        }
    }

    /**
     * 根据id或者number 更新一条单据信息
     * @param farmRecordsHarmlesses 请求的对象
     * @return  boolean (更新成功返回true 反之返回false)
     */
    @Override
    public Integer updateByIdOrNumber(FarmRecordsHarmlesses farmRecordsHarmlesses, Integer toStatus) {
        try {
            if (farmRecordsHarmlessesMapper == null){
                throw new OPServerException("farmRecordsHarmlessesMapper 为null,请检查");
            }
            farmRecordsHarmlesses.setStatus(toStatus);
            farmRecordsHarmlesses.setUpdated_at(new Date());
            Integer con = farmRecordsHarmlessesMapper.updateByPrimaryKeySelective(farmRecordsHarmlesses);

            List<FarmRecordsFile> farmRecordsFileList = farmRecordsFileService.selectPicOrVideoListByRelevanceIds(Lists.newArrayList(farmRecordsHarmlesses.getId()),FarmRecordsFileEnum.HARMLESSESNOCENTER.getCode(),Lists.newArrayList(FarmRecordsFileEnum.PHOTO.getCode(),FarmRecordsFileEnum.VIDEO.getCode()));

            if (farmRecordsFileList.size() > 0) {
                this.insertPicOrVideo(farmRecordsHarmlesses);
            } else {
                this.updatePicOrVideo(farmRecordsHarmlesses);
            }

            return con;
        } catch (Exception e) {
            log.error(e.getMessage());
            e.printStackTrace();
            throw new OPServerException(HttpCode.DATA_UPDATE_FAIL,HttpCode.DATA_UPDATE_FAIL.getMessage());
        }
    }

    /**
     * 自己做的无害化记录,需要新建生产记录单据对象
     */
    private FarmRecordsProduction createFarmRecordsProduction(FarmRecordsHarmlesses farmrecordsHarmlesses, Integer isFrom) {
        FarmRecordsProduction farmRecordsProduction = new FarmRecordsProduction();

        farmRecordsProduction.setRelate_type(ProductRelateTypeEnum.HARMLESS_TREATMENT.getCode());
        farmRecordsProduction.setRelate_id(farmrecordsHarmlesses.getId());
        farmRecordsProduction.setRelate_number(farmrecordsHarmlesses.getNumber());
        farmRecordsProduction.setStatus(FarmRecordsNumberStatus.TEMPORARY.getCode());
        farmRecordsProduction.setFarm_id(farmrecordsHarmlesses.getFarm_id());
        farmRecordsProduction.setFarm_name(farmrecordsHarmlesses.getFarm_name());

        if (farmrecordsHarmlesses.getStable_id() != null){
            farmRecordsProduction.setStable_id(farmrecordsHarmlesses.getStable_id());
            farmRecordsProduction.setStable_number(farmrecordsHarmlesses.getStable_number());
        }

        farmRecordsProduction.setArea(farmrecordsHarmlesses.getArea());

        farmRecordsProduction.setDate(new Date());
        farmRecordsProduction.setBirth_quantity(0);
        farmRecordsProduction.setIn_quantity(0);
        farmRecordsProduction.setOut_quantity(0);

        farmRecordsProduction.setBreed_type(farmrecordsHarmlesses.getBreed_type());
        farmRecordsProduction.setBreed_second_type(farmrecordsHarmlesses.getBreed_second_type());
        farmRecordsProduction.setBreed_third_type(farmrecordsHarmlesses.getBreed_third_type());
        farmRecordsProduction.setUnit(farmrecordsHarmlesses.getUnit());
        farmRecordsProduction.setDeath_quantity(farmrecordsHarmlesses.getQuantity());
        farmRecordsProduction.setChange_quantity(0 - farmrecordsHarmlesses.getQuantity());
        /*farmRecordsProduction.setDelete_flag(FarmRecordsNumberStatus.EFFECTIVE.getCode());*/

        return farmRecordsProduction;
    }

    private Integer insertPicOrVideo(FarmRecordsHarmlesses farmrecordsHarmlesses){
        Map<String,Object> map = Maps.newHashMap();
        map.put("type1",FarmRecordsFileEnum.HARMLESSESNOCENTER.getCode());
        map.put("relevance_id", farmrecordsHarmlesses.getId());

        List<String> picList = farmrecordsHarmlesses.getPicList();
        String video = farmrecordsHarmlesses.getVideo_toObject();

        String address = null;
        Integer type2 = null;

        if (picList != null && picList.size() > 0) {
            //插入图片
            type2 = FarmRecordsFileEnum.PHOTO.getCode();

            address = JSON.toJSONString(picList);
            map.put("type2",type2);
            map.put("address",address);

            farmRecordsFileMapper.insertPicOrVideoByRelevanceId(map);
        }

        map.remove(type2);
        map.remove(address);

        if (!Strings.isNullOrEmpty(video)) {
            //插入视频
            type2 = FarmRecordsFileEnum.VIDEO.getCode();

            map.put("type2",type2);
            map.put("address",video);

            farmRecordsFileMapper.insertPicOrVideoByRelevanceId(map);
        }

        return null;
    }

    private Integer updatePicOrVideo(FarmRecordsHarmlesses farmRecordsHarmlesses){
        Map<String,Object> map =Maps.newHashMap();
        map.put("type1",FarmRecordsFileEnum.HARMLESSESNOCENTER.getCode());
        map.put("relevance_id", farmRecordsHarmlesses.getId());

        List<String> picList = farmRecordsHarmlesses.getPicList();
        String video = farmRecordsHarmlesses.getVideo_toObject();

        String address = null;
        Integer type2 = null;

        if (picList != null && picList.size() > 0) {
            //更新图片
            type2 = FarmRecordsFileEnum.PHOTO.getCode();

            address = JSON.toJSONString(picList);
            map.put("type2",type2);
            map.put("address",address);

            farmRecordsFileMapper.updatePicOrVideoByRelevanceId(map);
        }

        map.remove(type2);
        map.remove(address);

        if (!Strings.isNullOrEmpty(video)) {
            //更新视频
            type2 = FarmRecordsFileEnum.VIDEO.getCode();

            map.put("type2",type2);
            map.put("address",video);

            farmRecordsFileMapper.updatePicOrVideoByRelevanceId(map);
        }

        return null;
    }

    /**
     * 更新耳标(耳标状态,耳标使用记录)
     * @param loginInfo
     * @param farmRecordsHarmlesses
     * @return
     */
    //@Override
    public Boolean updateEarNumber(LoginInfo loginInfo,FarmRecordsHarmlesses farmRecordsHarmlesses) {

        List<String> earNumberList = farmRecordsHarmlesses.getEar_tag_number();

        boolean after = false;

        //对新增耳标操作
        if (earNumberList.size() > 0) {
            List<String> earNumbers = Lists.newArrayList();
            for (String earNumber : earNumberList) {
                //循环判断耳标是否为空或空字符串
                if (Strings.isNullOrEmpty(earNumber)) {
                    earNumbers.add(earNumber);
                }
            }

            if (earNumbers.size() > 0) {
                //更新耳标的状态
                Map<String,Object> earParam = Maps.newHashMap();
                earParam.put("markNumbers",earNumbers);
                earParam.put("status", EarMarkType.status_output.getCode());
                earParam.put("outedAt",new Date());

                after = earMarksWriteService.updateMarks(earParam);

                //新增耳标的使用记录
                List<EarMarkLife> earMarkLiveList = Lists.newArrayList();
                for (String earNumber : earNumberList) {
                    EarMarkLife earMarkLife = new EarMarkLife();
                    earMarkLife.setMark_number(earNumber);
                    earMarkLife.setMark_type(farmRecordsHarmlesses.getBreed_second_type());
                    earMarkLife.setReport_id(farmRecordsHarmlesses.getId());
                    earMarkLife.setReport_name(farmRecordsHarmlesses.getNumber());
                    earMarkLife.setReport_type(ReportType.QUARANTINE_CENTER_HARMLESS.value());
                    earMarkLife.setIs_selected(1);
                    earMarkLife.setOperator_id(loginInfo.getId());
                    earMarkLife.setOperator_name(loginInfo.getRealName());
                    earMarkLife.setCreated_at(new Date());
                    earMarkLiveList.add(earMarkLife);
                }

                earMarkLifeWriteService.insertList(earMarkLiveList);
            }
        }

        return after;
    }

    @Override
    public List<Map<String, Object>> findAWeekSum(Map<String, Object> paramsMap) {
        return farmRecordsHarmlessesMapper.findAWeekSum(paramsMap);
    }
}
